<template>
  <div :id="idName" :style="{width:width,height:height}" />
</template>


<script>
export default {
  props: {
    idName: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '100%'
    },
    options: {
      type: Object,
      default: () => {}
    }
  },
  data () {
    return {
      chart: null
    }
  },
  mounted () {
    this.initChart()
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    // 释放图表实例
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart () {
      this.chart = this.$echarts.init(document.getElementById(this.idName))
      this.chart.setOption(this.options)
    }
  }
}
</script>

